var token = localStorage.getItem('tok');
$.ajax({
    type: "GET",
    url: $host + '/api/app/person/perUserInfo',
    data: {
        'token':$.cookie('token')
    },
    async: true,
    dataType: 'json',
    success: function (result) {
        var data=result.data.phone
        $('.init-box-ip').html(data);
    },
    error: function () {
        console.log('接口错误')
    }
});
//改绑手机号点击获取验证码
$('.getyzm').click(function(){
    var phone=$('.phone').val();
    if(phone==""){
        layer.msg('请输入手机号码');
        return false;
    }else if(!(/^1[34578]\d{9}$/.test(phone))){
        layer.msg('手机号码格式有误，请重新填写');
        return false;
    }else {
        $.ajax({
            type: "POST",
            url: $host + '/api/open/common/sendCode',
            data: {
                "phone": phone,
                "type": 3,
                'token':$.cookie('token')
            },
            async: true,
            dataType: 'json',
            success: function (result) {
                console.log(result);
            },
            error: function () {
                console.log('接口错误')
            }
        });
        codeButton();
        $('.init-box-btn').addClass("active");
    }
})
function codeButton(){
    var code = $(".getyzm");
    code.attr("disabled","disabled");
    setTimeout(function(){
        code.css("color","#DBDBDB");
    },1000)
    var time = 60;
    var set=setInterval(function(){
        code.text("重新获取"+--time+'s');
        //code.text(+--time+"秒后重新获取");
    }, 1000);
    setTimeout(function(){
        code.attr("disabled",false).text("重新获取");
        clearInterval(set);
    }, 60000);
}

//点击保存修改
$('.btn').click(function(){
    var phone=$('.phone').val();
    var code=$('.code').val();
    $.ajax({
        type: "POST",
        url: $host + '/api/app/person/perUserInfoUpdate',
        data: {
            "phone": phone,
            "code":code,
            'token':$.cookie('token'),
            'email':$.cookie('email'),
            'qqNum':$.cookie('qqNum')
        },
        async: true,
        dataType: 'json',
        success: function (result) {
            console.log(result);
            if(result.status===900000){
                $('.btn').addClass("active-btn");
            }else{
                layer.msg('改绑失败')
            }

        },
        error: function () {
            console.log('接口错误')
        }
    });
})
//点击返回
$('.gbsjhfh').click(function(){
    window.location.href="gerenxx.html?token="+token;
})